package com.lglbc.singelton;
/**
 * @author： 乐哥聊编程(全平台同号)
 */
public class LHPattern {

}

/**
 * 线程不安全 禁止使用
 */
class LHPatternThreadUnSafe{
    private static LHPatternThreadUnSafe INSTANCE;
    private LHPatternThreadUnSafe(){

    }

    public static LHPatternThreadUnSafe getInstance(){
        if (INSTANCE == null) {
            INSTANCE = new LHPatternThreadUnSafe();
            return INSTANCE;
        }
        return INSTANCE;
    }
}
/**
 * 同步方法
 */
class LHPatternThreadSafe{
    private static LHPatternThreadSafe INSTANCE;
    private LHPatternThreadSafe(){

    }

    public static synchronized LHPatternThreadSafe getInstance(){
        if (INSTANCE == null) {
            INSTANCE = new LHPatternThreadSafe();
            return INSTANCE;
        }
        return INSTANCE;
    }
}
/**
 * 同步代码块 不推荐使用
 */
class LHPatternThreadSafeCodeBlock{
    private static LHPatternThreadSafeCodeBlock INSTANCE;
    private LHPatternThreadSafeCodeBlock(){

    }

    public static LHPatternThreadSafeCodeBlock getInstance(){
        if (INSTANCE == null) {
            synchronized (LHPatternThreadSafeCodeBlock.class){
                INSTANCE = new LHPatternThreadSafeCodeBlock();
            }
            return INSTANCE;
        }
        return INSTANCE;
    }
}

/**
 * 同步代码块 双重检查
 */
class LHPatternThreadSafeDoubleCheck{
    private static LHPatternThreadSafeDoubleCheck INSTANCE;
    private LHPatternThreadSafeDoubleCheck(){

    }

    public static LHPatternThreadSafeDoubleCheck getInstance(){
        if (INSTANCE == null) {
            synchronized (LHPatternThreadSafeDoubleCheck.class){
                if (INSTANCE == null) {
                    INSTANCE = new LHPatternThreadSafeDoubleCheck();
                }
            }
            return INSTANCE;
        }
        return INSTANCE;
    }
}
/**
 * 同步代码块 volatile
 */
class LHPatternThreadSafeVolatile{
    private volatile static LHPatternThreadSafeVolatile INSTANCE;
    private LHPatternThreadSafeVolatile(){

    }
    public static LHPatternThreadSafeVolatile getInstance(){
        if (INSTANCE == null) {
            synchronized (LHPatternThreadSafeVolatile.class){
                if (INSTANCE == null){
                    INSTANCE = new LHPatternThreadSafeVolatile();
                }
            }
            return INSTANCE;
        }
        return INSTANCE;
    }
}
/**
 * 静态内部类
 */

class LHPatternInnerClass{
    static class LHPatternInnerClassInstance{
        private static final  LHPatternInnerClass INSTANCE = new LHPatternInnerClass();
    }
    public static LHPatternInnerClass getInstance(){
        return LHPatternInnerClassInstance.INSTANCE;
    }
}